package com.lxmes.sales.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.sales.domain.NcAssemblyPreSchedulingPlan;
import com.lxmes.sales.service.INcAssemblyPreSchedulingPlanService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 部装预排产计划Controller
 *
 * @author lx
 * @date 2023-04-11
 */
@RestController
@RequestMapping("/sales/assemblyPreSchedulingPlan")
public class NcAssemblyPreSchedulingPlanController extends BaseController
{
    @Autowired
    private INcAssemblyPreSchedulingPlanService ncAssemblyPreSchedulingPlanService;

    /**
     * 查询部装预排产计划列表
     */
    @PreAuthorize("@ss.hasPermi('sales:assemblyPreSchedulingPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcAssemblyPreSchedulingPlan ncAssemblyPreSchedulingPlan)
    {
        startPage();
        List<NcAssemblyPreSchedulingPlan> list = ncAssemblyPreSchedulingPlanService.selectNcAssemblyPreSchedulingPlanList(ncAssemblyPreSchedulingPlan);
        return getDataTable(list);
    }

    /**
     * 导出部装预排产计划列表
     */
    @PreAuthorize("@ss.hasPermi('sales:assemblyPreSchedulingPlan:export')")
    @Log(title = "部装预排产计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcAssemblyPreSchedulingPlan ncAssemblyPreSchedulingPlan)
    {
        List<NcAssemblyPreSchedulingPlan> list = ncAssemblyPreSchedulingPlanService.selectNcAssemblyPreSchedulingPlanList(ncAssemblyPreSchedulingPlan);
        ExcelUtil<NcAssemblyPreSchedulingPlan> util = new ExcelUtil<NcAssemblyPreSchedulingPlan>(NcAssemblyPreSchedulingPlan.class);
        util.exportExcel(response, list, "部装预排产计划数据");
    }

    /**
     * 获取部装预排产计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('sales:assemblyPreSchedulingPlan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncAssemblyPreSchedulingPlanService.selectNcAssemblyPreSchedulingPlanById(id));
    }

    /**
     * 新增部装预排产计划
     */
    @PreAuthorize("@ss.hasPermi('sales:assemblyPreSchedulingPlan:add')")
    @Log(title = "部装预排产计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcAssemblyPreSchedulingPlan ncAssemblyPreSchedulingPlan)
    {
        return toAjax(ncAssemblyPreSchedulingPlanService.insertNcAssemblyPreSchedulingPlan(ncAssemblyPreSchedulingPlan));
    }

    /**
     * 修改部装预排产计划
     */
    @PreAuthorize("@ss.hasPermi('sales:assemblyPreSchedulingPlan:edit')")
    @Log(title = "部装预排产计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcAssemblyPreSchedulingPlan ncAssemblyPreSchedulingPlan)
    {
        return toAjax(ncAssemblyPreSchedulingPlanService.updateNcAssemblyPreSchedulingPlan(ncAssemblyPreSchedulingPlan));
    }

    /**
     * 删除部装预排产计划
     */
    @PreAuthorize("@ss.hasPermi('sales:assemblyPreSchedulingPlan:remove')")
    @Log(title = "部装预排产计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncAssemblyPreSchedulingPlanService.deleteNcAssemblyPreSchedulingPlanByIds(ids));
    }
    @Log(title = "部装预排产计划", businessType = BusinessType.DELETE)
	@GetMapping("/formalProduction/{ids}")
    public AjaxResult formalProduction(@PathVariable Long[] ids)
    {
        return toAjax(ncAssemblyPreSchedulingPlanService.formalProduction(ids));
    }

    /**
     * 导入部装预排产计划
     */
    @Log(title = "部装预排产计划", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcAssemblyPreSchedulingPlan> util = new ExcelUtil<>(NcAssemblyPreSchedulingPlan.class);
        List<NcAssemblyPreSchedulingPlan> ncAssemblyPreSchedulingPlanList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncAssemblyPreSchedulingPlanService.imporIteminfo(ncAssemblyPreSchedulingPlanList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcAssemblyPreSchedulingPlan> util = new ExcelUtil<>(NcAssemblyPreSchedulingPlan.class);
        util.importTemplateExcel(response,"部装预排产计划");
    }


}
